<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <div id="app">
        <h2>1221</h2>
        <cpn @item-click='cpnClick'></cpn>
    </div>

    <template id="cpn">
        <div>
            <button v-for="item in categories"
                            @click="btnClick(item)">{{item.name}}</button>
        </div>
    </template>


    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script>
        const cpn = {
            template: '#cpn',
            data() {
                return {
                    categories: [
                        {id: 'aaa',  name: '热门推荐'},
                        {id: 'bbb', name: '手机数码'},
                        {id: 'ccc', name: '家用家电'},
                        {id: 'ddd', name: '电脑办公'},
                    ]
                }
            },
            methods: {
                btnClick(item) {
                    console.log(item)
                    this.$emit('item-click', item);
                }
            }
        }

        const app = new Vue({
            el: '#app',
            
            methods: {
                cpnClick(item) {
                    console.log('aaaa', item)
                }
            },

            components: {
                cpn
            }
            
        })
    </script>

</body>
</html>